home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-04-27 | 1.6 KB | 76 lines | [TEXT/CWIE] |
- /*
- ©1996 Peter N Lewis <peter@stairways.com.au>
- */
-
- package au.com.peter.libraries;
-
- // Generic AppletFrame
-
- import java.awt.*;
- import java.applet.Applet;
-
- // Applet to Application Frame window
- public class AppletFrame extends Frame {
-
- public static void startApplet(String className, String title, String args[]) {
- Applet a;
- Dimension appletSize;
-
- try {
- // create an instance of your applet class
- a = (Applet) Class.forName(className).newInstance();
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
- startApplet( a, title, args );
- }
-
- public static void startApplet(Applet a, String title, String args[]) {
- Dimension appletSize;
-
- // initialize the applet
- a.init();
- a.start();
-
- // create new application frame window
- AppletFrame f = new AppletFrame(title);
-
- // add applet to frame window
- f.add("Center", a);
-
- // resize frame window to fit applet
- // assumes that the applet sets its own size
- // otherwise, you should set a specific size here.
- appletSize = a.size();
- f.pack();
- f.resize(appletSize);
-
- // show the window
- f.show();
-
- } // end startApplet()
-
-
- // constructor needed to pass window title to class Frame
- public AppletFrame(String name) {
- // call java.awt.Frame(String) constructor
- super(name);
- }
-
- // needed to allow window close
- public boolean handleEvent(Event e) {
- // Window Destroy event
- if (e.id == Event.WINDOW_DESTROY) {
- dispose();
- return true;
- }
-
- // it's good form to let the super class look at any unhandled events
- return super.handleEvent(e);
-
- } // end handleEvent()
-
- } // end class AppletFrame
-
-